<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Cache;

class Beijing extends Controller
{

    private $area = '北京';
    private $areaid = 1;
    private $site = 'http://m.beijing.150.com';
    private $qq = '64745386';

    public function index(){
        $link = Db::name('link')->where('areaid',$this->areaid)->select();
        $this->assign('link',$link);
        $cat = Db::name('cat')->select();
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $ad = Db::name('info')->where('areaid',1)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',1)->select();
        $info = Db::name('info')
            ->alias('a')
            ->join('cat c','a.catid = c.cat')
            ->where('areaid',$this->areaid)
            ->order('ding desc')->select();
        $this->assign('cat',$cat);
        $this->assign('tui',$tui);
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $area = $this->area;
        $this->assign('qq',$this->qq);
        $site = $this->site;
        $this->assign('site',$site);
        return $this->fetch('index/index');
    }

    public function job(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('areaid',$areaid)
            ->where('catid',1)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/job');
    }


    public function zhaosheng(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('catid',2)
            ->where('areaid',$areaid)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/zhaosheng');
    }
//    招商
    public function zhaoshang(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('catid',4)
            ->where('areaid',$areaid)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/zhaoshang');
    }

//    微商
    public function weishang(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('catid',5)
            ->where('areaid',$areaid)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/weishang');
    }

//    生活服务
    public function shenghuo(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('catid',3)
            ->where('areaid',$areaid)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/shenghuo');
    }
//    互联网项目
    public function hulianwang(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $areaid =$this->areaid;
        $info = Db::name('info')
            ->where('catid',6)
            ->where('areaid',$areaid)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $this->assign('qq',$this->qq);
        return $this->fetch('index/hulianwang');
    }

    public function info(){
        $info = Db::name('info')->where('id',input('id'))->find();
        $this->assign('h',$info);
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $cate = Db::name('cat')->where('cat',$info['catid'])->find();
        $this->assign('cate',$cate);
        $ad = Db::name('info')->where('areaid',$this->area)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',$this->area)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);

        $area =  $this->area;
        $this->assign('area',$area);
        $site = $this->site;
        $this->assign('site',$site);
        $ding = Db::name('info')->order('ding desc')->limit(20)->select();

        $this->assign('ding',$ding);

        $message =  Db::name('message')->where('infoid',input('id'))->select();
        $user = Db::name('users')->where('id',$info['uid'])->find();
        $this->assign('u',$user);
        $this->assign('message',$message);

        return $this->fetch('index/info');
    }
    public function publish(){
        return $this->fetch('index/publish');
    }

    public function message(){
        if(input('post.')) {
            $mobile = input('mobile');
            $uid =  Db::name('info')->where('id',input('id'))->value('uid');
            Db::name('message')->insert([
                'uid'=>$uid,
                'infoid'=>input('id'),
                'mobile'=>$mobile,
                'time'=>time(),
            ]);
            $this->success('提交成功');
        }
    }
}